<script>
export default {
    props: ['modelValue'],
    emits: ['update:modelValue'],
    computed: {
        book: {
            get() {
                return this.modelValue
            },
            set(value) {
                this.$emit('update:modelValue', value)
            }
        }
    }
}
</script>

<template>
    <div class="book-form">
        <div>
            <label for="title">书名</label>
            <input type="text" id="title" v-model="book.title" />
        </div>
        <div>
            <label for="pic">封面</label>
            <input type="text" id="pic" v-model="book.pic" />
        </div>
        <div>
            <label for="author">作者</label>
            <input type="text" id="author" v-model="book.author" />
        </div>
        <div>
            <label for="publisher">出版社</label>
            <input type="text" id="publisher" v-model="book.publisher" />
        </div>
        <div>
            <label for="producer">出品方</label>
            <input type="text" id="producer" v-model="book.producer" />
        </div>
        <div>
            <label for="subtitle">副标题</label>
            <input type="text" id="subtitle" v-model="book.subtitle" />
        </div>
        <div>
            <label for="original-title">原作名</label>
            <input type="text" id="original-title" v-model="book.originalTitle" />
        </div>
        <div>
            <label for="translator">译者</label>
            <input type="text" id="translator" v-model="book.translator" />
        </div>
        <div>
            <label for="pubdate">出版日期</label>
            <input type="text" id="pubdate" v-model="book.pubdate" />
        </div>
        <div>
            <label for="pages">页数</label>
            <input type="text" id="pages" v-model="book.pages" />
        </div>
        <div>
            <label for="price">定价</label>
            <input type="text" id="price" v-model="book.price" />
        </div>
        <div>
            <label for="binding">装帧</label>
            <input type="text" id="binding" v-model="book.binding" />
        </div>
        <div>
            <label for="series">丛书</label>
            <input type="text" id="series" v-model="book.series" />
        </div>
        <div>
            <label for="isbn">ISBN</label>
            <input type="text" id="isbn" v-model="book.isbn" />
        </div>
        <div>
            <label for="douban-id">豆瓣ID</label>
            <input type="text" id="douban-id" v-model="book.doubanId" />
        </div>
        <div class="intro">
            <label for="intro">内容简介</label>
            <textarea type="text" id="intro" rows="10" v-model="book.intro"></textarea>
        </div>
        <div>
            <button @click="$emit('book-save')">提交</button>
        </div>
    </div>
</template>

<style scoped>
.book-form {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-start;
    align-items: center;
}

.book-form>div {
    flex: 1 1 30%;
    margin: 8px;
    display: flex;
    align-items: center;
    justify-content: flex-start;
}

.book-form>div.intro {
    min-width: 100%;
}

.book-form button {
    margin-left: 80px;
    width: 20%;
}

label {
    display: inline-block;
    width: 80px;
}

textarea,
input {
    flex: auto;
    box-sizing: border-box;
}
</style>